﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Test.Entities
{
	public class Website : Region
	{
		#region Fields

		private Domain _primaryDomain;
		private IList<Domain> _domains;

		#endregion

		#region Constructors

		//public Website()
		//{
		//}

		#endregion

		#region Properties

		[Required]
		[DisplayName(@"Website Type")]
		public WebsiteType Type { get; set; }

		public WebsiteConfiguration Configuration { get; set; }

		public IList<Domain> Domains
		{
			get
			{
				if (_domains == null)
				{
					_domains = new List<Domain>();
				}

				return _domains;
			}
			set
			{
				_domains = value ?? new List<Domain>();
			}
		}

		public Domain PrimaryDomain
		{
			get
			{
				if ((_primaryDomain == null || !_primaryDomain.IsPrimary) && Domains.Count > 0)
				{
					_primaryDomain = Domains.SingleOrDefault(d => d.IsPrimary);
				}

				return _primaryDomain;
			}
		}

		#endregion
	}
}